/*
 * Copyright (C) 2004, Velocityme Partnership
 * DataSourceConnection.java
 *
 * Created on 02 June 2004, 09:11
 */

package com.velocityme.utility;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author  Robert
 */
public class DataSourceConnection {
    
    private static DataSource m_cachedDataSource = null;
    
    public static Connection getConnection() throws NamingException, SQLException {
        if (m_cachedDataSource == null) {
            Context aJNDIContext = new InitialContext();
            String dataSource = ServerConfiguration.getInstance().getDataSource();
            m_cachedDataSource = (DataSource)aJNDIContext.lookup(dataSource);
        }
        return m_cachedDataSource.getConnection();
    }
    
}
